//
//  SLCommentCell.m
//  百思不得姐
//
//  Created by Anthony on 17/4/2.
//  Copyright © 2017年 SLZeng. All rights reserved.
//

#import "SLCommentCell.h"
#import "SLComment.h"
#import "SLUser.h"

#import "GlobalConst.h"
#import "UIImageView+SLCircleImage.h"
#import "UIImage+SLImageWithBundlePath.h"

@interface SLCommentCell()
@property (weak, nonatomic) IBOutlet UIImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UIImageView *sexView;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *likeCountLabel;
@property (weak, nonatomic) IBOutlet UIButton *voiceButton;
@end

@implementation SLCommentCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    UIImage *image = [UIImage sl_imageWithBundleForClass:[self class] imageNamed:@"mainCellBackground@2x.png"];
    self.backgroundView = [[UIImageView alloc] initWithImage:image];
}

- (void)setComment:(SLComment *)comment
{
    _comment = comment;
        
    self.usernameLabel.text = comment.user.username;
    self.contentLabel.text = comment.content;
    
    self.likeCountLabel.text = [NSString stringWithFormat:@"%zd", comment.like_count];
    [self.profileImageView sl_setCircleImageWithBundleForClass:[self class] URLString:comment.user.profile_image placeholderImageNamed:@"defaultUserIcon@2x.png"];
    
    NSString *sexImageName = [comment.user.sex isEqualToString:SLUserSexMale] ? @"Profile_manIcon@2x.png" : @"Profile_womanIcon@2x.png";
    self.sexView.image =  [UIImage sl_imageWithBundleForClass:[self class] imageNamed:sexImageName];
    
    if (comment.voiceuri.length) {
        self.voiceButton.hidden = NO;
        [self.voiceButton setTitle:[NSString stringWithFormat:@"%zd''", comment.voicetime] forState:UIControlStateNormal];
    } else {
        self.voiceButton.hidden = YES;
    }
}

@end
